<?php
/////////////////////////////////////////////////////////////////////////////
// 这个文件是 网城创想多用户商城 项目的一部分
//
// Copyright (c) 2007 - 2008 www.shopnc.net
//
// 要查看完整的版权信息和许可信息，请查看源代码中附带的 COPYRIGHT 文件，
// 或者访问 http://www.shopnc.net/ 获得详细信息。
/////////////////////////////////////////////////////////////////////////////

/**
 * FILE_NAME : own_shop.php   FILE_PATH : D:\webroot\mulitishop\member\own_shop.php
 * ....商铺管理
 *
 * @copyright Copyright (c) 2007 - 2007 www.shopnc.net 
 * @author 网城创想多用户商城开发团队 php_netproject@yahoo.com.cn
 * @package 
 * @subpackage 
 * @version Thu Sep 06 16:52:10 CST 2007
 */

require_once("../global.inc.php");

class OwnShopManage extends CommonFrameWork{
	/**
	 * 商铺对象
	 *
	 * @var obj
	 */
	var $obj_shop;
	/**
	 * 商铺分类对象
	 *
	 * @var obj
	 */
	var $obj_shopcategory;
	/**
	 * 验证对象
	 *
	 * @var obj
	 */
	var $objvalidate;
	/**
	 * 会员对象
	 *
	 * @var obj
	 */
	var $objmember;

	function main(){
		/**
		 * 创建商铺对象
		 */
		if (!is_object($this->obj_shop)){
			require_once("shop.class.php");
			$this->obj_shop = new ShopClass();
		}
		/**
		 * 创建商铺分类对象
		 */
		if (!is_object($this->obj_shopcategory)){
			require_once("shopcategory.class.php");
			$this->obj_shopcategory = new ShopCategoryClass();
		}
		/**
		 * 创建验证对象
		 */
		if (!is_object($this->objvalidate)){
			require_once("commonvalidate.class.php");
			$this->objvalidate = new CommonValidate();
		}

		/**
		 * 设置模板路径
		 */
		$this->setsubtemplates("member");

		/**
		 * 语言包
		 */
		$this->getlang("shop");

		$this->_input['hideMemberId'] = $_SESSION["s_login"]['id'];
		$this->_input['hideShopId'] = $_SESSION["s_shop"]['id'];

		/**
		 * 根据参数调用相应的方法
		 */
		switch ($this->_input['action']){
			case "modi":
				$this->shopMenuModule();
				$this->_getShopInfo();
				break;
			case "new":
				$this->_newShopInfo();
				break;
			case "save":
				$this->_saveShopInfo();
				break;
			case "dellogo":
				$this->_delLogo();
				break;
			case "intro":
				$this->shopMenuModule();
				$this->_getIntro();
				break;
			case "saveintro":
				$this->_saveShopIntro();
				break;
			default:
				$this->shopMenuModule();
				$this->_getShopInfo();
		}
	}

	/**
	 * 显示某商铺信息
	 *
	 */
	function _getShopInfo(){
		/**
		 * 获取商铺信息
		 */
		$shop_array = array();
		$shop_array = $this->obj_shop->getOneShop($_SESSION['s_shop']['id']);
		//echo $_SESSION['s_shop']['id'];
		/**
		 * 获取商铺的2级分类
		 */
		$category_array = $this->obj_shopcategory->getLevelCategory(2,0);
		/**
	     * 将商铺分类以下拉框的形式出现
	     */
		$select_category = Common::showForm_Select("slcShopClass","","",Common::getSelectArray($category_array,array('class_id','class_name')),$shop_array['shop_class']);
		// print_r($shop_array);
		$this->output("shop_select_category", $select_category);    //输出商铺分类以下拉框
		$this->output("shop_info", $shop_array);
		$this->showpage("own_shop.modi");
	}

	/**
	 * 新建一个商店
	 *
	 */
	function _newShopInfo(){
		$this->memberMenuModule();
		/**
		 * 获取商铺的2级分类
		 */
		$category_array = $this->obj_shopcategory->getLevelCategory(2,0);
		/**
	     * 将商铺分类以下拉框的形式出现
	     */
		$select_category = Common::showForm_Select("slcShopClass","","",Common::getSelectArray($category_array,array('class_id','class_name')));
		$this->output("shop_select_category", $select_category);    //输出商铺分类以下拉框
		$this->showpage("own_shop.add");   //显示页面
	}

	/**
	 * 开店商铺信息
	 * 店铺名称、店铺类目、店铺介绍
	 *
	 */
	function _saveShopInfo(){
		/**
		 * 检验输入信息
		 */
		$this->objvalidate->validateparam = array(
		array("input"=>$this->_input["hideMemberId"],"require"=>"true","message"=>$this->_lang['errCMemberNoLogin']), //您尚未登陆，请登陆
		array("input"=>$this->_input["txtShopName"],"require"=>"true","message"=>$this->_lang['errShopEnterName']), //请填写商店名称
		array("input"=>$this->_input["slcShopClass"],"require"=>"true","message"=>$this->_lang['errShopSelectClass']), //请选择商店分类
		//array("input"=>$this->_input["sale_range"],"require"=>"true","message"=>$this->_lang['errShopEnterSaleRange']), //请填写商店经营范围
		);

		/**
		 * 创建会员对象
		 */
		if (!is_object($this->objmember)){
			require_once ("member.class.php");
			$this->objmember = new MemberClass();
		}

		/**
		 * 检验的错误信息
		 */

		$error = $this->objvalidate->validate();

		if($error != ""){
			$this->redirectPath("error","",$error);
		}else{
			/**
			 * 上传店标图片
			 */
			if(isset($_FILES['fileShopLogo']['name'])){
				require_once("uploadfile.class.php");
				$upload = new UploadFile();
				$upload->allow_type = explode(',',$upload->_fileconfig['allowuploadimagetype']);   //允许上传的文件类型
				$upload->ifresize = false;   //是否产生缩略图
				$filename = $upload->upfile("fileShopLogo");
				$this->_input["fileShopLogo"] = $filename["getfilename"];//上传图片
			}
			$this->_configinfo['shopinfo']['ifcheck'];
			$this->_input['ischeck'] = $this->_configinfo['shopinfo']['ifcheck'];
			//print_r($this->_input);exit;
			$result = $this->obj_shop->operateShop($this->_input);  //把信息放入数据库中
			if ($this->_input['ischeck'] == "0"){
				$this->_input['member_type'] = "1";
				$_SESSION["s_login"]['type'] = "1";
				$shop_id = $this->obj_shop->getShopID($_SESSION['s_login']['name'],"login_name","1");  //得到商城ID
				//echo $shop_id;exit;
				if ($shop_id > 0){
					$_SESSION["s_shop"]['id'] = $shop_id;
				}
				$this->objmember->modifyMember($this->_input,$_SESSION['s_login']['id'],"type");
			}
			$this->redirectPath("succ","/member/own_main.php","填写商铺信息成功!");
		}
	}

	/**
	 * 删除商店店标
	 *
	 */
	function _delLogo(){
		/**
		 * 获取商铺信息
		 */
		$shop_array = array();
		$shop_array = $this->obj_shop->getOneShop($_SESSION['s_shop']['id']);

		/**
		 * 删除图片
		 */
		if (file_exists("../" . $shop_array['shop_pic'])){
			unlink("../" . $shop_array['shop_pic']);
		}
		/**
		 * 更新数据库
		 */
		$result = $this->obj_shop->operateShop(array('fileShopLogo'=>'null','hideShopId'=>2));
		$this->redirectPath("succ","/member/own_shop.php?action=modi","您已经删除商铺LOGO了!");
	}

	/**
	 * 得到店铺信息
	 *
	 */
	function _getIntro(){
		/**
		 * 获取商铺信息
		 */
		$shop_array = array();
		$shop_array = $this->obj_shop->getOneShop($_SESSION['s_shop']['id']);

		$this->output("shop_intro", $shop_array['shop_intro']);    //输出商铺介绍
		$this->showpage("own_shopintro.modi");   //显示页面
	}

	/**
	 * 保存店铺介绍
	 *
	 */
	function _saveShopIntro(){
		$this->_input['txtShopIntro'] = Common::replacebr($this->_input['txtShopIntro']);
		$result = $this->obj_shop->operateShop($this->_input);  //把信息放入数据库中
		$this->redirectPath("succ","/member/own_shop.php?action=intro","您已修改商铺介绍!");
	}
}

$shop_manage = new OwnShopManage();
$shop_manage->main();
unset($shop_manage);
?>